
#ifndef CWAVE_H
#define CWAVE_H

#include <stdint.h>
#include <QString>
#include <QByteArray>


#pragma pack(1)
typedef struct __WAVEDESCR
{
    char  riff[4];
    uint32_t size;
    char  wave[4];

} _WAVEDESCR, *_LPWAVEDESCR;

typedef struct __WAVEFORMAT
{
    char  id[4];
    uint32_t size;
    uint16_t format;
    uint16_t channels;
    uint32_t sampleRate;
    uint32_t byteRate;
    uint16_t blockAlign;
    uint16_t bitsPerSample;
    uint16_t extraFormatBytes;
} _WAVEFORMAT, *_LPWAVEFORMAT;
#pragma pack()


class CWave
{
public:
    CWave(void);
    virtual ~CWave(void);

public:
    // Public methods
    bool load(const QString & filePath);
    bool Save(const QString &filePath);
    bool Mix(CWave& wave);
    bool IsValid()              const         {return m_data.size();}
    const char * GetData()      const         {return m_data.data();}
    uint32_t GetSize()          const         {return m_data.size();}
    uint16_t GetChannels()      const         {return m_Format.channels;}
    uint32_t GetSampleRate()    const         {return m_Format.sampleRate;}
    uint16_t GetBitsPerSample() const         {return m_Format.bitsPerSample;}
    QString name()              const         {return m_name;}

    void setSampleRate(uint32_t sr)	          {m_Format.sampleRate = sr;}
    void setBitsPerSample(uint16_t bps)	      {m_Format.bitsPerSample = bps;}
    void setData(char * data, uint32_t size);
    void fillDescriptor();
    void fillFormat();
private:
    void clear();
    private:
    // Private members
    _WAVEDESCR m_Descriptor;
    _WAVEFORMAT m_Format;
    QByteArray m_data;
    QString m_name;
};

#endif//CWAVE_H
